<?php
/**
 *	Architect Framework
 *
 *	Architect Framework is a light weight object oriented web applications framework written for PHP 5.1.4 and later that provide the tools to develop and deploy a website or application fast and with as little code as possible.
 *
 *	@author Robin Grass, <hello@coffinboy.se>
 *	@link http://architect.kodlabbet.net
 *	@license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License (v. 3)
 */

/**
 *	Architect_TestSuite
 *
 *	This test suite tests the installed version and required libraries used by Architect.
 *
 *	@package Core
 *	@version 1.0
 *	@author Robin Grass, <hello@coffinboy.se>
 */
class Architect_TestSuite {
	
	protected $feature_tests = array();
	
	public function __construct() {
		$this->registerCallback('runtimeVersion', 'You need at least PHP 5.1.4 to be able to use Architect.');
		$this->registerCallback('hasSPL', 'You do not have SPL installed, which comes bundled with PHP5 so... There\'s something really weird with your PHP version.');
		$this->registerCallback('hasReflections', 'You need the Reflections API libraries installed.');
		$this->registerCallback('hasDOMXML', 'You need DOM/XML and XPath libraries installed.');
	}
	
	protected function registerCallback($fn, $error_message) {
		$this->feature_tests[$fn] = $error_message;
	}
	
	public function runTests() {
		foreach($this->feature_tests as $fn => $error_message) {
			if(call_user_func(array($this, $fn)) === false)
				exit("<strong>Missing feature</strong>: {$error_message}.");
		}
	}
	
	protected function runtimeVersion() {
		return (bool) (version_compare(PHP_VERSION, '5.1.4', '>='));
	}
	
	protected function hasExtension($extension) {
		return (bool) extension_loaded($extension);
	}
	
	protected function hasClass($class) {
		return (bool) class_exists($class, false);
	}
	
	protected function hasSPL() {
		return $this->hasExtension('SPL');
	}
	
	protected function hasReflections() {
		return $this->hasExtension('Reflection');
	}
	
	protected function hasDOMXML() {
		if(
			$this->hasExtension('libxml') &&
			$this->hasExtension('xml') &&
			$this->hasExtension('dom') &&
			$this->hasClass('DOMDocument') &&
			$this->hasClass('DOMXPath')) {
			return true;
		}
	return false;
	}

}

$test_suite = new Architect_TestSuite();
$test_suite->runTests();
?>